package com.shuwen.gcdj.common.util;

import cn.hutool.core.date.DateTime;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.util.Date;

public class RandomUtil {
    private static String prefix="BX";
    private static String suffix="-YJ";
    private static String wbPrefix="WB-";

    public static String randomCode(){
        DateTime dateTime = new DateTime(new Date());
        long time = dateTime.getTime();
        String s = String.valueOf(time);
        String substring = s.substring(0, 10);
        String random =prefix+substring +"01"+suffix;
        return random;
    }

    public static String WbCode(String code){
        Integer lenth =5;
        if (code.length()>16){
            lenth=lenth+code.length()-16;
        }
        LocalDate localDate = LocalDate.now();
        String now = localDate.toString();
        String replaced = now.replace("-", "");
        if(StringUtils.isEmpty(code)){
            String random =wbPrefix+replaced +"00001";
            return random;
        }else {
            String last = code.substring(code.length()-lenth);
            Integer i = Integer.parseInt(last) + 1;
            String substring = last.substring(last.length() - i.toString().length());
            String replace = last.replace(substring, i.toString());
            String random =wbPrefix+replaced +replace;
            return random;
        }

    }
}
